﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    pMusic=new musicWindow();
    setWindowFlag(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    pApp=(QApplication*)QApplication::instance();
    QFile fp(":/test.qss");
    if(fp.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        QTextStream style(&fp);
        QString qSty=style.readAll();
        pApp->setStyleSheet(qSty);
        fp.close();
    }
    ui->label->setType(0);
    ui->label_2->setType(1);
    connect(ui->label_2,&myLabel::qiehuan,this,&MainWindow::on_label_qiehuan);
    connect(ui->label,&myLabel::tuichu,this,&MainWindow::on_label_tuichu);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_label_tuichu()
{
    close();
}

void MainWindow::on_label_qiehuan()
{
    QString photoName=QFileDialog::getOpenFileName(
                this,
                "切换头像",
                "",
                "JPG(*.jpg);;PNG(*.png)");
    if(!photoName.isEmpty())
    {
        QPixmap headPho(photoName);
        ui->label_2->setPixmap(headPho);
        ui->label_2->setScaledContents(true);
    }
    else
    {
        qDebug("取消切换头像");
    }

}


void MainWindow::on_pushButton_clicked()
{
    pMusic->backWidget(this);
    pMusic->show();
    this->hide();
}

void MainWindow::on_pushButton_2_clicked()
{
    close();
}
